//package com.heroh.util;
//
//import com.mysql.cj.util.StringUtils;
//
//import java.io.UnsupportedEncodingException;
//import java.net.URLDecoder;
//import java.nio.charset.StandardCharsets;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
///**
// * 包名称：com.heroh.util
// * 类名称：url参数解析类
// * 类描述：配置工具类
// * 创建人：@author jianshengxiong
// * 创建时间：2020/1/9/15:58
// */
//public class ConnectionUrlParser {
//
//    private static final Pattern CONNECTION_STRING_PTRN = Pattern.compile("(?<scheme>[\\w:%]+)\\s*" // scheme: required; alphanumeric, colon or percent
//            + "(?://(?<authority>[^/?#]*))?\\s*" // authority: optional; starts with "//" followed by any char except "/", "?" and "#"
//            + "(?:/(?!\\s*/)(?<path>[^?#]*))?" // path: optional; starts with "/" but not followed by "/", and then followed by by any char except "?" and "#"
//            + "(?:\\?(?!\\s*\\?)(?<query>[^#]*))?" // query: optional; starts with "?" but not followed by "?", and then followed by by any char except "#"
//            + "(?:\\s*#(?<fragment>.*))?"); // fragment: optional; starts with "#", and then followed by anything
//
//    private String scheme;
//    private String authority;
//    private String path;
//    private String query;
//
//    public static ConnectionUrlParser parseConnectionString(String url) {
//        Matcher matcher = CONNECTION_STRING_PTRN.matcher(url);
//        if (!matcher.matches()) {
//            throw new RuntimeException("无效的URL");
//        }
//        ConnectionUrlParser parser = new ConnectionUrlParser();
//        parser.scheme = decode(matcher.group("scheme"));
//        parser.authority = matcher.group("authority"); // Don't decode just yet.
//        parser.path = matcher.group("path") == null ? null : decode(matcher.group("path")).trim();
//        parser.query = matcher.group("query"); // Don't decode just yet.
//        return parser;
//    }
//
//    /**
//     * URL-decode the given string.
//     *
//     * @param text the string to decode
//     * @return the decoded string
//     */
//    private static String decode(String text) {
//        if (StringUtils.isNullOrEmpty(text)) {
//            return text;
//        }
//        try {
//            return URLDecoder.decode(text, StandardCharsets.UTF_8.name());
//        } catch (UnsupportedEncodingException e) {
//            // Won't happen.
//        }
//        return "";
//    }
//
//    public String getScheme() {
//        return scheme;
//    }
//
//    public String getAuthority() {
//        return authority;
//    }
//
//    public String getPath() {
//        return path;
//    }
//
//    public String getQuery() {
//        return query;
//    }
//}
